from fastapi import FastAPI
from fastapi_cache import FastAPICache
from fastapi_cache.backends.redis import RedisBackend
from redis import asyncio as aioredis

from .auth.base_config import auth_backend, fastapi_users
from .auth.schemas import UserRead, UserCreate

from .operations.router import router as router_operation

app = FastAPI(
    title="Trading App"
)

app.include_router(
    fastapi_users.get_auth_router(auth_backend),
    prefix="/auth",
    tags=["Auth"],
)

app.include_router(
    fastapi_users.get_register_router(UserRead, UserCreate),
    prefix="/auth",
    tags=["Auth"],
)

app.include_router(router_operation)



@app.on_event("startup")
async def startup_event():
    redis = aioredis.from_url('redis://localhost', decode_responses=True, encoding='utf-8')
    FastAPICache.init(RedisBackend(redis), prefix="fastapi-cache")
